package com.codedef.diary.util;

import android.util.Log;

import java.io.IOException;

import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.Response;


public class NetWorkUtil {

    //"http://192.168.123.131:8085/user/getArticleList.php"

    public static String get(final String url, final String session) {
        String result = null;
        OkHttpClient client = new OkHttpClient();
        Request request = new Request.Builder()
                .url(url)
                .addHeader("Cookie", session)
                .build();
        Response response = null;
        try {
            response = client.newCall(request).execute();
            result = response.body().string();
            result = StringUtil.convertUnicodeToCh(result);
        } catch (IOException e) {
            e.printStackTrace();
        }
        return result;
    }

    public static String get(final String url) {
        String result = null;
        OkHttpClient client = new OkHttpClient();
        Request request = new Request.Builder()
                .url(url)
                .build();
        Response response = null;
        try {
            response = client.newCall(request).execute();
            result = response.body().string();
            result = StringUtil.convertUnicodeToCh(result);
        } catch (IOException e) {
            e.printStackTrace();
        }
        return result;
    }


}
